/**
 * 任务模型
 *
 * Created by snowingsea on 2020/03/03.
 */
const mongoose = require('mongoose');
const schemaDefinition = require('./schema/file-defect');
const schemaInstance = mongoose.Schema(schemaDefinition);
schemaInstance.index({ versionId: 1 });
schemaInstance.index({ fileId: 1 });
schemaInstance.index({ ruleId: 1 });
const modelInstance = mongoose.model('file-defect', schemaInstance);

if (!schemaInstance.options.toObject) schemaInstance.options.toObject = {};
schemaInstance.options.toObject.transform = function transform(doc, ret) {
  // remove the _id of every document before returning the result
  ret.defectId = ret._id.toHexString();
  delete ret._id;
  delete ret.__v;
  return ret;
};

/**
 * Export model definition object.
 */
module.exports = modelInstance;
